//
//  WMpingLunZan.swift
//  GZWeibo007
//
//  Created by 汪明 on 15/12/25.
//  Copyright © 2015年 Apple. All rights reserved.
//

import UIKit

class WMpingLunZan: UIView {

    var but: UIButton?
    var statu: CZStatus? {
    
        didSet{
        
            
            
            zan.setTitle("赞 \(statu!.attitudes_count)", forState: .Normal)
            
            pingLun.setTitle("评论 \(statu!.comments_count)", forState: .Normal)
            zhuanFa.setTitle("转发: \(statu!.reposts_count)", forState: .Normal)
            
            zan.setTitle("赞 \(statu!.attitudes_count)", forState: .Selected)
            
            pingLun.setTitle("评论 \(statu!.comments_count)", forState: .Selected)
            zhuanFa.setTitle("转发: \(statu!.reposts_count)", forState: .Selected)
            
            
            
        }
     
    }
    
    override func awakeFromNib() {
      
        
        self.pingLun.selected = true
        self.huatiao1.width = self.pingLun.width
        
        self.huatiao1.center.x = self.pingLun.center.x

        
    }
    
    var refreshPingLun: (()->())?
     var refreshZan: (()->())?
     var refreshZhuanFa: (()->())?
    @IBOutlet weak var zan: UIButton!
    @IBOutlet weak var pingLun: UIButton!
    @IBOutlet weak var zhuanFa: UIButton!
    
    @IBOutlet weak var huatiao1: UILabel!

    @IBOutlet weak var layou: NSLayoutConstraint!
   
    
    
    
    
    @IBAction func 转发(sender: UIButton) {
        
        refreshZhuanFa!()
        but?.selected = false
        
        but = sender
         sender.selected = !sender.selected
        self.pingLun.selected = false
       
        UIView.animateWithDuration(0.25) { () -> Void in
           
            self.layoutIfNeeded()
             self.huatiao1.width = self.zhuanFa.width
           self.huatiao1.center.x = self.zhuanFa.center.x
          
            
        }
    }
    
    @IBAction func 评论(sender: UIButton) {
        
        if sender.selected {
        
          refreshPingLun!()
            
            return
        
        }
        but?.selected = false
       
        but = sender
        sender.selected = !sender.selected
        
        UIView.animateWithDuration(0.25) { () -> Void in
           self.layoutIfNeeded()
            self.huatiao1.width = self.pingLun.width

            self.huatiao1.center.x = self.pingLun.center.x
                }
        
    }
    
    @IBAction func 赞(sender: UIButton) {
        
        refreshZan!()
       self.pingLun.selected = false
        but?.selected = false
        
        but = sender
        
         sender.selected = !sender.selected
        UIView.animateWithDuration(0.25) { () -> Void in
           
            self.layoutIfNeeded()
             self.huatiao1.width = self.pingLun.width
            self.huatiao1.center.x = self.zan.center.x
           
        }

    }
    
}
